function [id] = readDemographics(fn)


% Get filename and look for student ID
dashes = strfind(fn,'-');
sid=fn(dashes(5)+1:dashes(6)-1);

% Look for file with Demographics and student ID
pathtofiles = '/Volumes/300GB iceCUBE G2/DataEmotion/EmotionExp';
demog = rdir([pathtofiles '/**/*Demographics*.txt']);
demFilename = [];
for i = 1:length(demog)
  if strfind(demog(i).name,sid)
    demFilename =  demog(i).name;
  end
end
if isempty(demFilename)
  disp([' Cannot find a demographics file to match ' fn]);
  id = 'continue';
  return;
end

% read file
fidDem=fopen(demFilename);
while 1
  dt= fgetl(fidDem);
  if ~ischar(dt), break, end
  lastLine = dt;
end
fclose(fidDem);


[path,fndemog] = fileparts(demFilename);
numID = strrep(fndemog,'-Demographics','');
numIDPos = strfind(lastLine,numID);
lastLine= lastLine(numIDPos(end):end);
clear('SID');
SIDpos = strfind(numID,'-');
SID    = numID(SIDpos(end)+1:end);
dems = textscan(lastLine,'%s%f%f%f%f%s%d%d%q%q%q%q');

disp(SID);
% Set variables for the demographics
id.id = dems{1};
id.age = dems{2} + dems{3}/12;
id.mus = dems{4} + dems{5}/12;
id.gender = dems{6};
faveFace = dems{7};
worstFace = dems{8};
lang = [char(dems{9}) ' ' char(dems{10}) ' ' char(dems{11}) ' ' char(dems{12})];

